home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / comm / comm1 / klrkcmsr.lha / Comment_Select.C < prev    next >
C/C++ Source or Header  |  1995-12-17  |  9KB  |  288 lines

  1. #define COMMENT_SELECT
  2.  
  3. #include "Comment.H"
  4.  
  5. BOOL SelectReceiver ( void )
  6. {
  7.     char    Temp[ 300 ], Time[ 40 ];
  8.     int    i, j , y = 8 , home = 10, lines_on_screen = 4, max_lines;
  9.     int    header_lines=0;
  10.     long    t;
  11.     struct Node *node;
  12.     BOOL    quit = FALSE, select_a_user, double_space = FALSE;
  13.  
  14.     FILE    *header;
  15.  
  16.     // Enable cursor control
  17.     putuserstring ( "" , 501 );
  18.  
  19.     // Display header
  20.     sm ( CLS , 0 );
  21.  
  22.     if ( gn_ptr->gn_header[ 0 ] != 0x00 )
  23.     {
  24.         header = fopen( gn_ptr->gn_header , "r" );
  25.         if ( header )
  26.         {
  27.             do
  28.             {
  29.                 fgets( Temp , sizeof( Temp ) , header );
  30.                 if ( ! feof( header ) )
  31.                 {
  32.                     strcat( Temp , "\r" );
  33.                     sm( Temp , 0 );
  34.                     lines_on_screen++;
  35.                     header_lines++;
  36.                 }
  37.             } while ( ! feof( header ) );
  38.             sm( "\n\r" , 0 );
  39.             lines_on_screen++;
  40.             header_lines++;
  41.             fclose( header );
  42.         }
  43.     }
  44.     else
  45.         lines_on_screen += 3;
  46.  
  47.     // What conference are we in? What's the max. number of lines a user
  48.     // can have on his screen?
  49.     getuserstring( gn_ptr->gn_confname , BB_CONFNAME );
  50.     getuserstring( Temp , DT_LINELENGTH );
  51.     max_lines = atoi( Temp );
  52.  
  53.     // Make up for the lost line while displaying header (why? don't know)
  54.     if ( gn_ptr->gn_header[ 0 ] != 0x00 )
  55.         lines_on_screen += 1;
  56.  
  57.     // Do we use two lines per receiver or not?
  58.     if ( lines_on_screen + ( gn_ptr->gn_total_users * 2 ) + 3 <= max_lines )
  59.         double_space = TRUE;
  60.  
  61.     // What's the time?
  62.     time( &t );
  63.     sprintf( Time , ctime( &t ) );
  64.  
  65.     // Strip the trailing return
  66.     Time[ strlen( Time ) -1 ] = 0x00;
  67.  
  68.     // Clear the screen and put the intro on screen
  69.     if ( gn_ptr->gn_header[ 0 ] == 0x00 )
  70.         sm("               KiLLER COMMENT v1.4 (c) 1995 by KiLLraVeN/MYSTiC\n\r\n\r" , 0 );
  71.     else
  72.         header_lines -= 2;
  73.  
  74.     // Set cursor-bar location for first receiver on screen
  75.     y += header_lines;
  76.  
  77.     sm(".--------------------------.---------------------------------------.---------.\n\r" , 0 );
  78.     sprintf( Temp , ": %24.24s Conf: %-31.31s MYSTiC:\n\r" , Time , gn_ptr->gn_confname );
  79.     sm( Temp , 0 );
  80.     sm("`--------------------------^---------------------------------------^---------'\n\r.--------------------------.-------------------------------------------------.\n\r" , 0 );
  81.     
  82.     // Now we need to put every user on screen, we take in account if there
  83.     // is a possibility to display a clear line between every user, this is
  84.     // done for cosmetic reasons only.
  85.     for ( node = (struct Node *) KC_Users0List.mlh_Head ; node->ln_Succ; node = node->ln_Succ )
  86.     {
  87.         rc_node = (struct receiver_node *) node;
  88.         sprintf( Temp , "  %2d%-20.20s   %s\n\rA" , rc_node->rc_number , rc_node->rc_knownas , rc_node->rc_info );
  89.         sm( Temp , 0 );
  90.         sm( "|C|C|\n\r" , 0 );
  91.         if ( double_space && rc_node->rc_number < gn_ptr->gn_total_users )
  92.         {
  93.             if ( ! line_separator )
  94.                 sm("|                          |                                                 |\n\r" , 0 );
  95.             else
  96.                 sm("|--------------------------|-------------------------------------------------|\n\r" , 0 );
  97.             home++;
  98.             lines_on_screen++;
  99.         }
  100.         home++;
  101.         lines_on_screen++;
  102.     }
  103.  
  104.     // The bottom part will take up another 4 lines
  105.     lines_on_screen += 4;
  106.  
  107.     // Put them on screen
  108.     sm("`--------------------------^-------------------------------------------------'\n\r" , 0 );
  109.     sm(".-------------------------------------------------------------.--------------.\n\r" , 0 );
  110.     if ( lines_on_screen <= max_lines )
  111.         sprintf( Temp , ": CURSOR KEYS / 1 - %2d / [SPACE] FOR DEFAULT SYSOP / [Q] QUIT SELECTED:    :\n\r" , gn_ptr->gn_total_users );
  112.     else
  113.         sprintf( Temp , ": USE NUM KEY / 1 - %2d / [SPACE] FOR DEFAULT SYSOP / [Q] QUIT SELECTED:    :\n\r" , gn_ptr->gn_total_users );
  114.     sm( Temp , 0 );
  115.     sm("`-------------------------------------------------------------^--------------'\n\r" , 0 );
  116.  
  117.     // Set the rc_node pointer to the first user in the list
  118.     rc_node = (struct receiver_node *) KC_Users0List.mlh_Head;
  119.  
  120.     // While the user doesn't select anything or doesn't want to quit, we
  121.     // stay in this loop, taking care of cursor control (if any) and screen
  122.     // building.
  123.     while ( ! quit )
  124.     {
  125.         // If the number of lines on screen is bigger than the number of lines
  126.         // a user can handle on screen, we need to disable the cursor control
  127.         // because it will totally fail. If not, we put the current user in
  128.         // a blue background with white characters.
  129.         if ( lines_on_screen <= max_lines )
  130.         {
  131.             sprintf( Temp , "%d;6H>%-20.20s" , y , rc_node->rc_knownas );
  132.             sm ( Temp , 0 );
  133.         }
  134.  
  135.         /* TESTING ONLY !
  136.         sprintf( Temp, "on_screen: %ld - max: %ld" , lines_on_screen , max_lines );
  137.         sm( Temp , 0 );
  138.         */
  139.  
  140.         // We put our cursor at the bottom of the screen, displaying the number
  141.         // of the currently active user.
  142.         sprintf( Temp , "%d;75H%2d" , home + header_lines , rc_node->rc_number );
  143.         sm ( Temp , 0 );
  144.         
  145.         // Now it's time to wait for input from the user
  146.         hk ( "" , Temp );
  147.         Temp[ 1 ] = 0x00;
  148.  
  149.         switch ( Temp[ 0 ] )
  150.         {
  151.             case    ' ':    // This function will select the FIRST user as the default
  152.                             // sysop and will exit the door.
  153.                             sprintf( Temp , "%d;6H %-20.20s" , y , rc_node->rc_knownas );
  154.                             sm ( Temp , 0 );
  155.                             rc_node = (struct receiver_node *) KC_Users0List.mlh_Head;
  156.                             select_a_user = TRUE;
  157.                             quit = TRUE;
  158.                             break;
  159.  
  160.             case 0x1B:    // ESC Key
  161.             case   3 :    // CTRL-C
  162.             case     'q':
  163.             case    'Q':     // The user obviously wants to quit. That's possible.
  164.                             // In order to do so gently, we remove any blue background
  165.                             // on the current user.
  166.                             select_a_user = FALSE;
  167.                             quit = TRUE;
  168.                             sprintf( Temp , "%d;6H %-20.20s" , y , rc_node->rc_knownas );
  169.                             sm ( Temp , 0 );
  170.                             break;
  171.  
  172.             case     13:    // RETURN key
  173.                             // The user wants to write to the current user. We de-select
  174.                             // the user on screen (blue background) and exit the door.
  175.                             sprintf( Temp , "%d;6H %-20.20s" , y , rc_node->rc_knownas );
  176.                             sm ( Temp , 0 );
  177.                             quit = TRUE;
  178.                             select_a_user = TRUE;
  179.                         break;
  180.  
  181.             case   5    :    // Cursor Down
  182.                             // If cursor control is possible, we move one user down.
  183.                             // If we are already on the bottom user, we will move to
  184.                             // the first one again.
  185.                             if ( lines_on_screen <= max_lines )
  186.                             {
  187.                                 sprintf( Temp , "%d;6H %-20.20s" , y , rc_node->rc_knownas );
  188.                                 sm ( Temp , 0 );
  189.                                 if ( (struct Node *) rc_node->nn_Node.ln_Succ != (struct Node *) &KC_Users0List.mlh_Tail )
  190.                                 {
  191.                                     rc_node = (struct receiver_node *) rc_node->nn_Node.ln_Succ;
  192.                                     if ( double_space )
  193.                                         y += 2;
  194.                                     else
  195.                                         y++;
  196.                                 }
  197.                                 else
  198.                                 {
  199.                                     rc_node = (struct receiver_node *) KC_Users0List.mlh_Head;
  200.                                     y = 8 + header_lines;
  201.                                 }
  202.                             }
  203.                             break;
  204.  
  205.             case   4    :    // Cursor Up
  206.                             // If cursor control is possible, we move one user up. If we
  207.                             // are at the top user, we move to the last one in the list.
  208.                             if ( lines_on_screen <= max_lines )
  209.                             {
  210.                                 sprintf( Temp , "%d;6H %-20.20s" , y , rc_node->rc_knownas );
  211.                                 sm ( Temp , 0 );
  212.                                 if ( (struct Node *) rc_node->nn_Node.ln_Pred != (struct Node *) &KC_Users0List.mlh_Head )
  213.                                 {
  214.                                     rc_node = (struct receiver_node *) rc_node->nn_Node.ln_Pred;
  215.                                     if ( double_space )
  216.                                         y -= 2;
  217.                                     else
  218.                                         y--;
  219.                                 }
  220.                                 else
  221.                                 {
  222.                                     rc_node = (struct receiver_node *) KC_Users0List.mlh_TailPred;
  223.                                     if ( double_space )
  224.                                         y = header_lines + 8 + ( ( gn_ptr->gn_total_users - 1 ) * 2 );
  225.                                     else
  226.                                         y = 8 + gn_ptr->gn_total_users - 1 + header_lines;
  227.                                 }
  228.                             }
  229.                             break;
  230.  
  231.             default    :    // It wasn't a cursor key, it wasn't the return key,
  232.                             // nor a space. Then it must be a number. If it is,
  233.                             // we will make the number entered the current user.
  234.                             // If there are more than 10 users, we will check
  235.                             // if it's possible that the previously entered
  236.                             // number is the first number of a 10+ number.
  237.                             i = atoi ( Temp );
  238.                             if ( gn_ptr->gn_total_users < 10 )
  239.                                 i = atoi ( Temp );
  240.                             else
  241.                             {
  242.                                 j = gn_ptr->gn_total_users / 10;
  243.                                 if (     rc_node->rc_number <=  j &&
  244.                                         ( ( 10 * rc_node->rc_number ) + i <= gn_ptr->gn_total_users ) )
  245.                                     i += ( 10 * rc_node->rc_number );
  246.                             }
  247.                             if ( i > 0 )
  248.                             {
  249.                                 if ( i <= gn_ptr->gn_total_users )
  250.                                 {
  251.                                     if ( lines_on_screen < max_lines )
  252.                                     {
  253.                                         sprintf( Temp , "%d;6H %-20.20s" , y , rc_node->rc_knownas );
  254.                                         sm ( Temp , 0 );
  255.                                     }
  256.                                     j = 1;
  257.                                     if ( double_space )
  258.                                         y = 6 + header_lines;
  259.                                     else
  260.                                         y = 7 + header_lines;
  261.                                     for ( node = (struct Node *) KC_Users0List.mlh_Head ; node->ln_Succ; node = node->ln_Succ , j ++ )
  262.                                     {
  263.                                         if ( double_space )
  264.                                             y += 2;
  265.                                         else
  266.                                             y++;
  267.                                         if ( j == i )
  268.                                         {
  269.                                             rc_node = (struct receiver_node *) node;
  270.                                             break;
  271.                                         }
  272.                                     }
  273.                                 }
  274.                             }
  275.                             break;
  276.         }
  277.     }
  278.  
  279.     // We are out of the loop, we put our cursor back at the bottom of the
  280.     // screen and display the selection.
  281.     sprintf( Temp , "%d;75H%2d" , home + header_lines , rc_node->rc_number );
  282.     sm ( Temp , 0 );
  283.  
  284.     // One line down and exit this routine
  285.     sm("B",1);
  286.     return ( select_a_user );
  287. }
  288.